import java.sql.* ;

class ProductCategory
{
	CreateConnection cc ;

	int cid ; // index-1
	String cname ; // index-2


	ProductCategory()
	{

		try{

						cc = new CreateConnection() ;

						}
						catch(Exception e)
			{}
	}


	void insertNewCategory(String[] s)// throws Exception
	{
		try
		{
		cid = Integer.parseInt(s[0]) ;
		cname = s[1] ;

		String sql = "insert into pcategory values(?,?)" ;

		PreparedStatement p = cc.getStatement(sql) ;

		p.setInt(1,cid) ;
		p.setString(2,cname) ;

		int x = p.executeUpdate() ;
				 if(x>0)
		  System.out.println("ProductCategory inserted successfully") ;
	}
	catch(Exception e)
	{
		System.out.println(e.getMessage());
	}


	}

	void updateCategory(String[] s) throws Exception
		{
			cid = Integer.parseInt(s[0]) ;
			cname = s[1] ;

			String sql = "update pcategory set cname=? where cid=? " ;

			PreparedStatement p = cc.getStatement(sql) ;

			p.setInt(2,cid) ;
			p.setString(1,cname) ;

			int x = p.executeUpdate() ;
					 if(x>0)
		  System.out.println("Product Category updated successfully") ;

	}


	ResultSet getCategories() throws Exception
	{

		String sql = "select * from pcategory" ;


		PreparedStatement p = cc.getStatement(sql) ;

		return p.executeQuery() ;
	}


	ResultSet getCategories(int id) throws Exception
		{

			String sql = "select * from pcategory where cid = ?" ;


			PreparedStatement p = cc.getStatement(sql) ;

			p.setInt(1,id) ;
			return p.executeQuery() ;
	}




}